package engine.j2d;

/**
 * @author    Yabi
 */

public class Rectangle 
{
	  public float x=0;
	  public float y=0;
	  public float width=0;
	  public float height=0;
	  public Rectangle()
	  {
		  this(0,0,0,0);
	  }
	  public Rectangle(float x,float y,float width,float height)
	  {
		  setBounds(x, y, width, height);
	  }
	  public void setBounds(float x,float y,float width,float height)
	  {
		  this.x=x;
		  this.y=y;
		  this.width=width;
		  this.height=height;
	  }
	  public Rectangle getBounds()
	  {
		  return new Rectangle(x,y,width,height);
	  }
	  public boolean intersects(Rectangle r) 
	  {
		  float tw = this.width;
		  float th = this.height;
		  float rw = r.width;
		  float rh = r.height;
		  if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) 
		  {
			  return false;
		  }
		  float tx = this.x;
		  float ty = this.y;
		  float rx = r.x;
		  float ry = r.y;
		  rw += rx;
		  rh += ry;
		  tw += tx;
		  th += ty;
		  return ((rw < rx || rw > tx) &&
				  (rh < ry || rh > ty) &&
				  (tw < tx || tw > rx) &&
				  (th < ty || th > ry));
	   }
}
